import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'
import Login from '@/views/Login/index.vue'
import NotFind from '@/views/Error/404.vue'
import NoAuth from '@/views/Error/401.vue'
import { setGuard } from './guard'
import {Icon} from "@iconify/vue";

export const constantRoutes: RouteRecordRaw[] = [
  {
    path: '/login',
    name: 'Login',
    component: Login,
    meta: {
      hidden: true,
      title: '登录',
    },
  },
  {
    path: '/',
    name: '首页',
    component: () => import('@/views/Layout/index.vue'),
    redirect: '/home',
    meta: {
      title: '首页',
      icon: () => h(Icon, { icon: 'solar:home-outline' }),
    },
    children: [
      {
        path: 'home',
        name: 'Home',
        component: () => import('@/views/Home/index.vue'),
      },
    ],
  },
  {
    path: '/Article',
    name: 'Article',
    meta: {
      title: '文章模块',
      icon: () => h(Icon, { icon: 'hugeicons:book-edit' }),
    },
    redirect: '/Article/ArticleDetail',
    component: () => import('@/views/Layout/index.vue'),
    children: [
      {
        path: 'ArticleDetail',
        name: 'ArticleDetail',
        meta: {
          title: '文章详情',
          icon: () => h(Icon, { icon: 'stash:article-light' }),
        },
        component: () => import('@/views/Article/index.vue'),
      },
      {
        path: 'ArticleLiked',
        name: 'ArticleLiked',
        meta: {
          title: '点赞列表',
          icon: () => h(Icon, { icon: 'stash:article-light' }),
        },
        component: () => import('@/views/Article/LikedList.vue'),
      },

      {
        path: 'ArticleSearch',
        name: 'ArticleSearch',
        meta: {
          title: '搜索',
          icon: () => h(Icon, { icon: 'stash:article-light' }),
        },
        component: () => import('@/views/Article/Search.vue'),
      },
    ]
  },
  {
    path: '/Question',
    name: 'Question',
    meta: {
      title: '问答模块',
      icon: () => h(Icon, { icon: 'stash:question-light' }),
    },
    redirect: '/Question/Circle',
    component: () => import('@/views/Layout/index.vue'),
    children: [
      {
        path: 'Circle',
        name: 'Circle',
        meta: {
          title: '圈子',
          icon: () => h(Icon, { icon: 'stash:question-light' }),
        },
        component: () => import('@/views/Planet/index.vue'),
      },
      {
        path: 'MyMoment',
        name: 'MyMoment',
        meta: {
          title: '我的动态',
          icon: () => h(Icon, { icon: 'stash:question-light' }),
        },
        component: () => import('@/views/Planet/MyMoment.vue'),
      },
    ]
  },
  {
    path:'/prize',
    name: 'Prize',
    meta: {
      title: '奖品模块',
      icon: () => h(Icon, { icon: 'stash:question-light' }),
    },
    redirect: '/prize/PrizeList',
    component: () => import('@/views/Layout/index.vue'),
    children: [
      {
        path: 'prizeList',
        name: 'PrizeList',
        meta: {
          title: '奖品列表',
          icon: () => h(Icon, { icon: 'stash:question-light' }),
        },
        component: () => import('@/views/Prize/index.vue'),
      },
     {
        path: 'MyPrize',
        name: 'MyPrize',
        meta: {
          title: '我的奖品',
          icon: () => h(Icon, { icon: 'stash:question-light' }),
        },
        component: () => import('@/views/Prize/MyPrize.vue'),
     }
    ]
  },
  {
    path:'/ai',
    name: 'Ai',
    meta: {
      title: 'AI模块',
      icon: () => h(Icon, { icon: 'stash:question-light' }),
    },
    redirect: '/ai/AiChat',
    component: () => import('@/views/Layout/index.vue'),
    children: [
      {
        path: 'AiChat',
        name: 'AiChat',
        meta: {
          title: 'AI聊天',
          icon: () => h(Icon, { icon: 'stash:question-light' }),
        },
        component: () => import('@/views/AiChat/index.vue'),
      }
    ]
  },
  {
    path: '/Private',
    name: 'Private',
    meta: {
      title: '私密模块',
      icon: () => h(Icon, { icon: 'stash:question-light' }),
    },
    redirect: '/Private/Chat',
    component: () => import('@/views/Layout/index.vue'),
    children: [
      {
        path: 'Chat',
        name: 'Chat',
        meta: {
          title: '私聊',
          icon: () => h(Icon, { icon: 'stash:question-light' }),
        },
        component: () => import('@/views/PrivateChat/index.vue'),
      },
    ]
  },
  {
    path: '/401',
    name: 'NoAuth',
    component: NoAuth,
    meta: {
      title: '401',
      hidden: true,
    },
  },
  {
    path: '/:pathMatch(.*)*',
    name: 'not-found',
    component: NotFind,
    meta: {
      title: '404',
      hidden: true,
    },
  },
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [...constantRoutes],
})

setGuard(router)
export default router
